{
  LW Generic -- LightWave Generic Commands

  Based on lwgeneric.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Generic;

{$mode delphi}{$H+}

interface

uses
  LW_Server,
  LW_Host  ,
  LW_Types ,
  LW_Dyna  ;

const
  LWLAYOUTGENERIC_CLASS   = 'LayoutGeneric';
  LWLAYOUTGENERIC_VERSION = 5;

type
  PLWLayoutGeneric = ^TLWLayoutGeneric;
  TLWLayoutGeneric = record
    SaveScene        : function
                       (const File_   : PChar         ) : Integer       ;
    LoadScene        : function
                       (const File_   : PChar         ;
                        const Name    : PChar         ) : Integer       ;

    Data             : Pointer;

    LookUp           : function
                       (      Data    : Pointer       ;
                        const CmdName : PChar         ) : TLWCommandCode;
    Execute          : function
                       (      Data    : Pointer       ;
                              Cmd     : TLWCommandCode;
                              ArgC    : Integer       ;
                        const ArgV    : PDynaValue    ;
                              Result_ : PDynaValue    ) : Integer       ;
    Evaluate         : function
                       (      Data    : Pointer       ;
                        const Command : PChar         ) : Integer       ;
    CommandArguments : function
                       (      Data    : Pointer       ) : PChar         ;
  end;

  { TLayoutGeneric }

  TLayoutGeneric = class
  protected
    class
    var
      FSelf : Pointer;

    class
    var
      FLayoutGeneric : PLWLayoutGeneric;
  public
    constructor
             Create
             (      Name    : PChar               ;
                    TagInfo : PServerTagInfo = nil) ;

    class
    function Activate
             (      Version    : Integer    ;
                    Global     : TGlobalFunc;
                    Local      : Pointer    ;
                    ServerData : Pointer    ) : Integer       ; static ;

    function Run                              : Integer       ; virtual;

    function SaveScene
             (const File_   : PChar         ) : Integer       ;
    function LoadScene
             (const File_   : PChar         ;
              const Name    : PChar         ) : Integer       ;
    function LookUp
             (const CmdName : PChar         ) : TLWCommandCode;
    function Execute
             (      Cmd     : TLWCommandCode;
                    ArgC    : Integer       ;
              const ArgV    : PDynaValue    ;
                    Result_ : PDynaValue    ) : Integer       ;
    function Evaluate
             (const Command : PChar         ) : Integer       ;
    function CommandArguments                 : PChar         ;
  end;

implementation

{ TLayoutGeneric }

function TLayoutGeneric.SaveScene
                        (const File_   : PChar         ) : Integer       ;
begin
  Result := FLayoutGeneric.SaveScene(File_);
end;

function TLayoutGeneric.LoadScene
                        (const File_   : PChar         ;
                         const Name    : PChar         ) : Integer       ;
begin
  Result := FLayoutGeneric.LoadScene(File_, Name);
end;

function TLayoutGeneric.LookUp
                        (const CmdName : PChar         ) : TLWCommandCode;
begin
  Result := FLayoutGeneric.LookUp(
            FLayoutGeneric.Data,  CmdName);
end;

function TLayoutGeneric.Execute
                        (      Cmd     : TLWCommandCode;
                               ArgC    : Integer       ;
                         const ArgV    : PDynaValue    ;
                               Result_ : PDynaValue    ) : Integer       ;
begin
  Result := FLayoutGeneric.Execute(
            FLayoutGeneric.Data,   Cmd, ArgC, ArgV, Result_);
end;

function TLayoutGeneric.Evaluate
                        (const Command : PChar         ) : Integer       ;
begin
  Result := FLayoutGeneric.Evaluate(
            FLayoutGeneric.Data,    Command);
end;

function TLayoutGeneric.CommandArguments                 : PChar         ;
begin
  Result := FLayoutGeneric.CommandArguments(
            FLayoutGeneric.Data             );
end;

constructor
         TLayoutGeneric.Create
                        (      Name    : PChar         ;
                               TagInfo : PServerTagInfo) ;
begin
  AddHandler(Name, LWLAYOUTGENERIC_CLASS, TActivateFunc(Activate), TagInfo);
  FSelf := Self;
end;

class
function TLayoutGeneric.Activate
                        (      Version    : Integer    ;
                               Global     : TGlobalFunc;
                               Local      : Pointer    ;
                               ServerData : Pointer    ) : Integer       ;
begin
  LWMessage := TLWMessage.Create(Global);

  FLayoutGeneric := Local;
  TLayoutGeneric(FSelf).Run;

  Result := AFUNC_OK;
end;

function TLayoutGeneric.Run                              : Integer       ;
begin
end;

end.
